package com.controller;

import com.pojo.Paper;
import com.pojo.R;
import com.service.PaperService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/paper")
public class PaperController {
    @Autowired
    private PaperService paperservice;

    @RequestMapping("/allPaper")
    public R list() {
        List<Paper> list = paperservice.queryAllPaper();
        return R.ok(list);
    }

    @PostMapping("/addPaper")
    public R addPaper(@RequestBody Paper paper) {
        paperservice.addPaper(paper);
        return R.ok();
    }

    @PostMapping("/del/{paperId}")
    public R deletePaper(@PathVariable("paperId") Long id) {
        paperservice.deletePaperById(id);
        return R.ok();
    }

    @PostMapping("/updatePaper")
    public R update(@RequestBody Paper paper) {
        paperservice.updatePaper(paper);
        paper = paperservice.queryById(paper.getPaperId());
        return R.ok(paper);
    }

    @GetMapping("/getPaperById")
    public R getPaperById(@RequestParam("id") long id) {
        Paper paper = paperservice.queryById(id);
        return R.ok(paper);
    }
}
